package secretary;

import home.HomePage;
import includes.Sessions;

import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;


import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.model.Model;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

import controllers.BKCashAdvance;
import controllers.Logs;
import controllers.StudentInformation;

public class ViewProfile extends WebPage{
	
	Reader reader = Resources.getResourceAsReader("sqlMapConfig.xml");
	SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
	
	
	public ViewProfile(String id) throws IOException, SQLException
	{
		add(new BookmarkablePageLink("home", SecretaryHome.class));
		add(new BookmarkablePageLink("logoutPage", HomePage.class));
		
		final String studentid= id;
		StudentInformation info = (StudentInformation)sqlMap.queryForObject("StudentInformation.MyInformation", studentid);
	
		Form form = new Form("viewForm");
		
		String name = info.getStudent_firstName() + " " + info.getStudent_middleName() + " " + info.getStudent_lastName();
		form.add(new Label("name", name ));
		form.add(new Label("studentId", studentid ));
		form.add(new Label("yearlevel", info.getStudent_yearlvl() ));
		form.add(new Label("gender", info.getStudent_gender() ));
		form.add(new Label("birthday", info.getStudent_birthdate() ));
		form.add(new Label("address", info.getStudent_address()));
		form.add(new Label("contact", info.getStudent_contNo() ));
		form.add(new Label("hobby", info.getStudent_hobby() ));
		form.add(new Label("dateCreated", info.getDate_created() ));
	
		final String uploadby = ((Sessions)getSession()).getDesc();
		
		Date today = new Date();
		Timestamp timestamp = new Timestamp(today.getTime());
		final String ts = timestamp.toString();
		
		form.add(new Button("edit"){
			private static final long serialVersionUID = 1L;

			public void onSubmit(){
			  try{
		
				EditProfile page = new EditProfile(studentid);
				setResponsePage(page);
				
			  }catch(SQLException e){
				  e.printStackTrace();
			  }catch(IOException e){
				  e.printStackTrace();
			  }
			}
		});
	
		add(form);
	}

}
